13. 练习:WITH

WITH 练习
本质上, WITH 语句和 子查询 执行的任务相同。因此,你可以使用 WITH 编写之前的任何一个查询。尝试使用 WITH (而不是子查询)再次执行之前的每个查询。
以上是数据库的 ERD,当你处理下面的练习时,可能会用到该 ERD。你应该将答案写成 WITH 语句,而不是得出一个答案并复制输出。这么做的重要性是查询能够动态地回答问题,即使数据变化了,依然能获得正确的答案。
-
提供每个 区域 拥有最高销售额 ( total_amt_usd ) 的 销售代表 的 姓名 。
-
对于具有最高销售额 ( total_amt_usd ) 的区域,总订单量是多少(注:订单量这里指购买货物总数)?
-
对于购买标准纸张数量 ( standard_qty ) 最多的客户(在作为客户的整个时期内), 有多少客户 的购买总数( total )比该用户的购买总数( total )更多?
-
对于(在作为客户的整个时期内)总消费 ( total_amt_usd ) 最多的客户,他们在每个渠道上有多少 web_events ?
-
对于总消费前十名的客户,他们的平均终身消费 ( total_amt_usd ) 是多少?
-
比所有客户的平均消费高的企业平均终身消费 ( total_amt_usd ) 是多少?
Workspace
This section contains either a workspace (it can be a Jupyter Notebook workspace or an online code editor work space, etc.) and it cannot be automatically downloaded to be generated here. Please access the classroom with your account and manually download the workspace to your local machine. Note that for some courses, Udacity upload the workspace files onto https://github.com/udacity , so you may be able to download them there.
Workspace Information:
- Default file path:
- Workspace type: sql-evaluator
- Opened files (when workspace is loaded): n/a